Visualization for Area Unit Data

Spring 2023

Author

Serge Rey

Published

February 23, 2023

Statistical Visualization of Area Unit Data

Geovisualization

Choropleths

Areal Unit Data

import geopandas
import libpysal
/tmp/ipykernel_38057/1387931905.py:1: UserWarning: Shapely 2.0 is installed, but because PyGEOS is also installed, GeoPandas will still use PyGEOS by default for now. To force to use and test Shapely 2.0, you have to set the environment variable USE_PYGEOS=0. You can do this before starting the Python process, or in your code before importing geopandas:

import os
os.environ['USE_PYGEOS'] = '0'
import geopandas

In a future release, GeoPandas will switch to using Shapely by default. If you are using PyGEOS directly (calling PyGEOS functions on geometries from GeoPandas), this will then stop working and you are encouraged to migrate from PyGEOS to Shapely 2.0 (https://shapely.readthedocs.io/en/latest/migration_pygeos.html).
  import geopandas
south = libpysal.examples.load_example('South')
libpysal.examples.explain('South')
south_gdf = geopandas.read_file(south.get_path('south.shp'))
south_gdf.plot()
<Axes: >

import seaborn
seaborn.displot(south_gdf, x='HR60')
<seaborn.axisgrid.FacetGrid at 0x7fb4b0593a60>

south_gdf.explore(column='HR60')
Make this Notebook Trusted to load map: File -> Trust Notebook
south_gdf.HR60.describe()
count    1412.000000
mean        7.292144
std         6.421018
min         0.000000
25%         3.213471
50%         6.245125
75%         9.956272
max        92.936803
Name: HR60, dtype: float64
south_gdf.plot(column='HR60')
<Axes: >

south_gdf.plot(column='HR60', scheme='Quantiles')
<Axes: >

south_gdf.plot(column='HR60', scheme='Quantiles', legend=True)
<Axes: >

Classification Schemes

import mapclassify
mapclassify.Quantiles(south_gdf.HR60)
Quantiles

   Interval      Count
----------------------
[ 0.00,  2.50] |   283
( 2.50,  5.10] |   282
( 5.10,  7.62] |   282
( 7.62, 10.98] |   282
(10.98, 92.94] |   283
mapclassify.Quantiles(south_gdf.HR60, k=10)
Quantiles

   Interval      Count
----------------------
[ 0.00,  0.00] |   180
( 0.00,  2.50] |   103
( 2.50,  3.93] |   141
( 3.93,  5.10] |   141
( 5.10,  6.25] |   141
( 6.25,  7.62] |   141
( 7.62,  9.19] |   141
( 9.19, 10.98] |   141
(10.98, 14.31] |   141
(14.31, 92.94] |   142

Map Customization

  • Legends
  • Color Schemes

Legends

south_gdf[['STATE_NAME', 'HR60', 'HR90']].head()
STATE_NAME HR60 HR90
0 West Virginia 1.682864 0.946083
1 West Virginia 4.607233 1.234934
2 West Virginia 0.974132 2.621009
3 West Virginia 0.876248 4.461577
4 Delaware 4.228385 6.712736
south_gdf['increased' ] =  south_gdf.HR90 > south_gdf.HR60
south_gdf.plot(column='increased', categorical=True, legend=True);

v = south_gdf.increased.map({True: 'Increased', False: 'Decreased'})
south_gdf['Increased'] = v
south_gdf.plot(column='Increased', categorical=True, legend=True);

south_gdf.plot(column='Increased', categorical=True, legend=True,
               legend_kwds={'bbox_to_anchor': (1.3, 1)});

south_gdf.plot(column='Increased', categorical=True, legend=True,
               legend_kwds={'bbox_to_anchor': (1.3, 1),
                           'title':'Homicide Rates 1960-1990'},
           );

south_gdf.plot(column='Increased', categorical=True, legend=True,
               legend_kwds={'bbox_to_anchor': (0, 1),
                           'title':'Homicide Rates 1960-1990'},
           );

south_gdf.plot(column='Increased', categorical=True, legend=True,
               legend_kwds={'bbox_to_anchor': (-0.1, 1),
                           'title':'Homicide Rates 1960-1990'},
           );

Qualitative Color Scheme

south_gdf.plot(column='STATE_NAME', categorical=True)
<Axes: >

south_gdf.plot(column='STATE_NAME', categorical=True, legend=True)
<Axes: >